package com.sneakxy.cloudbase.platform.utils.web;

import org.apache.commons.lang3.StringUtils;

public class StringUtilsExt {

	public static final String SETTER_PREFIX = "set";
	
	public static final String GETTER_PREFIX = "get";
	
	public static String upperCaseFirst(String s) {
		String first = StringUtils.substring(s, 0, 1);
		return StringUtils.join(StringUtils.upperCase(first), StringUtils.substring(s, 1));
	}
	
	public static String lowerCaseFirst(String s) {
		String first = StringUtils.substring(s, 0, 1);
		return StringUtils.join(StringUtils.lowerCase(first), StringUtils.substring(s, 1));
	}
	
	public static String setter(String fieldName) {
		return StringUtils.join(SETTER_PREFIX, upperCaseFirst(fieldName));
	}
	
	public static String getter(String fieldName) {
		return StringUtils.join(GETTER_PREFIX, upperCaseFirst(fieldName));
	}
	
	public static String formatStringName(String str) {
		String name = StringUtils.lowerCase(str);
		StringBuilder s = new StringBuilder();
		if(StringUtils.contains(name, "_")) {
			String[] parts = StringUtils.split(name, "_");
			for(String part:parts) {
				s.append(upperCaseFirst(part));
			}
		} else {
			s.append(upperCaseFirst(name));
		}
		return s.toString();
	}
	
	public static boolean isMobile(String number) {
		if(StringUtils.length(number) != 11) {
			return false;
		}
		if(!StringUtils.startsWith(number, "1")) {
			return false;
		}
		return StringUtils.isNumeric(number);
	}
	
	private StringUtilsExt() {}
	
}
